package com.dy.mongo;

import com.dy.mongo.service.CsvImportService;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

@SpringBootApplication
public class MongoApplication {

    public static void main(String[] args) {
        SpringApplication.run(MongoApplication.class, args);
    }

    @Bean
    CommandLineRunner importCsvRunner(CsvImportService service) {
        return args -> {
            // 根据实际路径修改，如 resources 目录或外部配置
            Path characters = Paths.get("characters.csv");
            Path relations  = Paths.get("relations.csv");
            if (Files.exists(characters) && Files.exists(relations)) {
                service.importCharactersAndRelations(characters, relations);
            }
        };
    }
}
